package gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.JComboBox;
import javax.swing.ListModel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BoxLayout;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class VSuscripciones extends JPanel {

	Object[] s = new Object[5];
	
	private JList list;
	
	/**
	 * Create the panel.
	 */
	public VSuscripciones() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{139, 0};
		gridBagLayout.rowHeights = new int[]{31, 97, 0};
		gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblSuscripciones = new JLabel("Subscripciones");
		GridBagConstraints gbc_lblSuscripciones = new GridBagConstraints();
		gbc_lblSuscripciones.insets = new Insets(0, 0, 5, 0);
		gbc_lblSuscripciones.gridx = 0;
		gbc_lblSuscripciones.gridy = 0;
		add(lblSuscripciones, gbc_lblSuscripciones);
		
		JScrollPane scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 1;
		add(scrollPane, gbc_scrollPane);
		
		for(int i = 0;i<5;i++)
		{
			final Integer j = i;
			s[i] =	new Object(){
				String t = new String("Usuario"+j);
				int id = j;
				public String toString(){
					return t;
				}
			};
		}
		
		
		list = new JList(s);
		list.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e){
				   if(e.getClickCount() == 2){
				     int index = list.locationToIndex(e.getPoint());
				     ListModel dlm = list.getModel();
				     Object item = dlm.getElementAt(index);;
				     list.ensureIndexIsVisible(index);
				     System.out.println("Double clicked on " + item);
				     }
				   }
		}
		);
		scrollPane.setViewportView(list);

	}
}
